package com.swt.gap.controller;

import com.swt.gap.model.entity.AchievementClass;
import com.swt.gap.service.AchievementClassService;
import com.swt.gap.util.UserLoginUtils;
import io.swagger.annotations.*;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author sx
 */
@Api(tags = "500. 战果类别相关")
@RestController
@RequestMapping("/achievement-class")
@Slf4j
public class AchievementClassController {

    private final AchievementClassService achievementClassService;

    public AchievementClassController(AchievementClassService achievementClassService) {
        this.achievementClassService = achievementClassService;
    }

    @PostMapping
    @ApiOperation(value = "新建分类", notes = "新建分类")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "record", dataType = "AchievementClass",paramType = "body")
    })
    @ApiResponses({@ApiResponse(code = 201, message = "created", response = Integer.class)})
    public ResponseEntity<Integer> addAchievementClass(@RequestBody AchievementClass record){
        record.setCreatedBy(UserLoginUtils.getUserId());
        return ResponseEntity.ok(achievementClassService.addAchievementClass(record));
    }

    @GetMapping
    @ApiOperation(value = "获取类别列表", notes = "获取类别列表")
    @ApiResponses({@ApiResponse(code = 200, message = "ok", response = AchievementClass.class, responseContainer = "List")})
    public ResponseEntity<List<AchievementClass>> listAllAchievementClass(){
        return ResponseEntity.ok(achievementClassService.listAllAchievementClass());
    }

    @PutMapping("/{achievementClassId}")
    @ApiOperation(value = "修改分类", notes = "修改分类")
    @ApiImplicitParams({
        @ApiImplicitParam(name = "achievementClassId", dataType = "int",paramType = "path", value = "战果分类Id"),
        @ApiImplicitParam(name = "record", dataType = "AchievementClass",paramType = "body")
    })

    @ApiResponses({@ApiResponse(code = 200, message = "ok", response = Integer.class)})
    public ResponseEntity<Integer> updateAchievementClass(@PathVariable Integer achievementClassId,
                                                          @RequestBody AchievementClass record){
        record.setAchievementClassId(achievementClassId);
        return ResponseEntity.ok(achievementClassService.updateAchievementClass(record));
    }

    @DeleteMapping("/{achievementClassId}")
    @ApiOperation(value = "删除分类以及分类下的战果", notes = "删除分类以及分类下的战果")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "achievementClassId", dataType = "int",paramType = "path", value = "战果分类Id")
    })
    @ApiResponses({@ApiResponse(code = 200, message = "ok", response = Integer.class)})
    public ResponseEntity<Integer> deleteAchievementClassAndAchievement(@PathVariable Integer achievementClassId){
        return ResponseEntity.ok(achievementClassService.deleteAchievementClassAndAchievement(achievementClassId));
    }

}
